package thread;

public class VariableVisiableTest {
	
    private static boolean ready;
    private static int number;
 
    private static class ReaderThread extends Thread {
        public void run() {
            if(ready == true && number == 0){
                System.out.println(ready);
                System.out.println(number);
            }
        }
    }
 
    private static class WriterThread extends Thread {
        public void run() {
            number = 100;
            ready = true;
        }
    }
 
    public static void main(String[] args) throws InterruptedException {
        while(true){
            Thread read = new ReaderThread();
            Thread write = new WriterThread();
            read.start();
            write.start();
            read.join();
            write.join();
            synchronized (VariableVisiableTest.class){
                ready = false;
                number = 0;
            }
        }
    }
}
